// Copyright 2023 Leo <lipf160627@163.com>. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.

package model

import "github.com/go-playground/validator/v10"

// 用户携带IP信息登录，可以实现一个用户多个client登录与控制
// redis cache设计：
//     1、采用hash
//     2、key：ID
//     3、field key：IP
//     4、value：jwt

// Login request
// swagger:model
type LoginRequest struct {
	Email    string `json:"email" validate:"required,email"`
	Password string `json:"password" validate:"required,min=6,max=16"`
	IP       string `json:"ip" validate:"ip"`
}

// Login response
// swagger:model
type LoginResponse struct {
	ID        uint   `json:"id" validate:"required"`
	Token     string `json:"token" validate:"required"`
	ExpiresAt int64  `json:"expiresAt" validate:"required"`
	Message   string `json:"message" validate:"required"`
}

// Logout request
// swagger:model
type LogoutRequest struct {
	ID uint   `json:"id" validate:"required"`
	IP string `json:"ip" validate:"ip"`
}

// Logout response
// swagger:model
type LogoutResponse struct {
	Message string `json:"message" validate:"required"`
}

func (r *LoginRequest) Validate(v *validator.Validate) error {
	return v.Struct(r)
}

func (r *LoginResponse) Validate(v *validator.Validate) error {
	return v.Struct(r)
}

func (r *LogoutRequest) Validate(v *validator.Validate) error {
	return v.Struct(r)
}

func (r *LogoutResponse) Validate(v *validator.Validate) error {
	return v.Struct(r)
}
